﻿#region

using System.IO;
using System.Text.RegularExpressions;

#endregion


namespace OMS.Ice.T4Generator.Syntax
{
    internal class IncludeDirective : Directive
    {
        public IncludeDirective( Match match )
            : base( match )
        {
        }

        public string File
        {
            get { return Attributes["file"]; }
        }

        public string Name
        {
            get { return Path.GetFileNameWithoutExtension( File ); }
        }

        public IncludeMode Mode
        {
            get
            {
                if(!Attributes.ContainsKey( "mode" ))
                    return IncludeMode.Inline;
                
#if !FRAMEWORK35
                IncludeMode mode;
                return IncludeMode.TryParse(Attributes["mode"], out mode) ? mode : IncludeMode.Inline;
#else
                try
                {
                    return (IncludeMode)Enum.Parse(typeof(IncludeMode), Attributes["mode"]);
                }
                catch
                {
                    return IncludeMode.Inline;
                }
#endif
            }
        }

        public override bool Equals(object obj)
        {
            var toCompare = obj as IncludeDirective;

            return toCompare != null && Name.Equals( toCompare.Name ) && Mode.Equals( toCompare.Mode );
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }
    }
}